﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Antlers
{
	internal class Lock
	{
		internal delegate void RunSafeDelegate();
		internal delegate bool RunSafeCondition();

		internal static void RunSafe(object lockObject, RunSafeCondition condition, RunSafeDelegate callback)
		{
			if (condition())
			{
				lock (lockObject)
				{
					if (condition())
					{
						callback();
					}
				}
			}
		}

		internal static void RunSafe(object lockObject, RunSafeDelegate callback)
		{
			lock (lockObject)
			{
				callback();
			}
		}
	}
}